﻿using FortuneUniverse.Fortune.Algorithms;

namespace FortuneUniverse.Fortune.Dyson
{
  public class PlanetAlgorithm8 : PlanetAlgorithm
  {
    public override void GenerateTerrain(double modX, double modY)
    {
      double num1 = 0.002 * modX;
      double num2 = 0.002 * modX * modX * 6.66667;
      double num3 = 0.002 * modX;
      SimplexNoise simplexNoise = new SimplexNoise(new URandom1(this.planet.seed).Next());
      PlanetRawData data = this.planet.data;
      for (int index = 0; index < data.dataLength; ++index)
      {
        double num4 = (double) data.vertices[index].x * (double) this.planet.radius;
        double num5 = (double) data.vertices[index].y * (double) this.planet.radius;
        double num6 = (double) data.vertices[index].z * (double) this.planet.radius;
        float num7 = Mathf.Clamp((float) (simplexNoise.Noise3DFBM(num4 * num1, num5 * num2, num6 * num3, 6, 0.45, 1.8) + 1.0 + modY * 0.00999999977648258), 0.0f, 2f);
        float num8;
        if ((double) num7 < 1.0)
        {
          float f = Mathf.Cos(num7 * 3.141593f) * 1.1f;
          num8 = (float) (1.0 - ((double) Mathf.Clamp(Mathf.Sign(f) * Mathf.Pow(f, 4f), -1f, 1f) + 1.0) * 0.5);
        }
        else
        {
          float f = Mathf.Cos((float) (((double) num7 - 1.0) * 3.14159274101257)) * 1.1f;
          num8 = (float) (2.0 - ((double) Mathf.Clamp(Mathf.Sign(f) * Mathf.Pow(f, 4f), -1f, 1f) + 1.0) * 0.5);
        }
        double num9 = (double) num8;
        data.heightData[index] = (ushort) (((double) this.planet.radius + num9 + 0.1) * 100.0);
      }
    }
  }
}
